/**
 * @description tab组件渲染元素
 */
import { h, VNode } from 'snabbdom';
import { IDomEditor, SlateElement, DomEditor } from '@wangeditor/editor';
import {TagElement} from "./types";

/**
 * @description 渲染tag
 * @param elem
 * @param children
 * @param editor
 * @returns VNode
 */
function renderTag(elem: SlateElement, children: VNode[] | null, editor: IDomEditor): VNode {
  const { value, className } = elem as TagElement;
  const selected = DomEditor.isNodeSelected(editor, elem);
  if (selected) {
    editor.move(1);
  }
  //创建vnode节点
  const vnode = h("span", {
    props: {
      contentEditable: false, // 不可编辑
    },
    className: className || ""
  }, value);
  return vnode;
}
const renderElem = {
  type: "tag",
  renderElem: renderTag
};
export default renderElem;
